<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth.js";
import { initializeRouter } from "@/utils/index.js";

export default {
  created() {
    this.loadMenu();
  },
  methods: {
    loadMenu() {
      if (getToken()) {
        this.$api.common.getUserMenu()
          .then((res) => {
            if (res.code === 200) {
              let route = initializeRouter(res.data);
              console.log("格式化后路由:", route);
              this.$store.commit("setRoutes", route);
              this.$router.options.routes = route;
              this.$router.addRoutes(route);
              this.$store.dispatch("GetInfo");
            }
          });
      }
    }
  },
};
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
